using System.Text;

namespace RadioTimer.Services
{
    /// <summary>
    /// 自定义Debug类，用于捕获Debug.WriteLine输出并记录到日志服务中
    /// </summary>
    public static class DebugLogger
    {
        private static ILogService? _logService;
        
        /// <summary>
        /// 初始化DebugLogger
        /// </summary>
        /// <param name="logService">日志服务实例</param>
        public static void Initialize(ILogService logService)
        {
            _logService = logService;
        }
        
        /// <summary>
        /// 写入日志信息
        /// </summary>
        /// <param name="message">日志消息</param>
        public static void WriteLine(string message)
        {
            System.Diagnostics.Debug.WriteLine(message);
            _logService?.Log(message, "Debug");
        }
        
        /// <summary>
        /// 写入日志信息
        /// </summary>
        /// <param name="format">格式化字符串</param>
        /// <param name="args">参数</param>
        public static void WriteLine(string format, params object[] args)
        {
            var message = string.Format(format, args);
            System.Diagnostics.Debug.WriteLine(message);
            _logService?.Log(message, "Debug");
        }
        
        /// <summary>
        /// 写入错误日志信息
        /// </summary>
        /// <param name="message">错误消息</param>
        public static void WriteError(string message)
        {
            System.Diagnostics.Debug.WriteLine($"[ERROR] {message}");
            _logService?.Log(message, "Error");
        }
        
        /// <summary>
        /// 写入警告日志信息
        /// </summary>
        /// <param name="message">警告消息</param>
        public static void WriteWarning(string message)
        {
            System.Diagnostics.Debug.WriteLine($"[WARNING] {message}");
            _logService?.Log(message, "Warning");
        }
    }
}